#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <functional>
using namespace std;

class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<int> st;
        map<string, function<int(int, int)>> opMap;
        opMap.emplace("+", [](int x, int y)->int {return x + y; });
        opMap.emplace("-", [](int x, int y)->int {return x - y; });
        opMap.emplace("*", [](int x, int y)->int {return x * y; });
        opMap.emplace("/", [](int x, int y)->int {return x / y; });

        for (auto& str : tokens)
        {
            if (opMap[str])
            {
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();
                st.push(opMap[str](left, right));
            }
            else
            {
                st.push(stoi(str));
            }
        }

        return st.top();
    }
};

int main()
{
    vector<string> arr({ "2", "1", "+", "3", "*" });
    cout << Solution().evalRPN(arr) << endl;

    return 0;
}